package com.wocao.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wocao.entity.ReqBody;
import com.wocao.entity.ZyCommunity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 小区  Mapper 接口
 *
 * @since 2023-11-29
 */
public interface ZyCommunityMapper extends BaseMapper<ZyCommunity> {

    //分页查询+搜索
    Page<ZyCommunity> selectAllZyCommunitys(Page page, @Param("reqBody") ReqBody reqBody);

    //通过id查询小区
    ZyCommunity selectCommunityById(@Param("communityId") String communityId);

    /**
     * 根据id查询社区名称
     * @param communityId communityId
     */
    void selectNameById(String communityId);

    @Update("UPDATE zy_community set dept_id = #{deptId} where community_id = #{communityId} ")
    //更换物业
    void editDeptId(@Param("communityId")String communityId,@Param("deptId")String deptId);


    //小程序-根据业主id查询
    @Select("SELECT c.community_name,c.community_id FROM `zy_owner_room` o " +
            " join zy_community c on o.community_id=c.community_id " +
            " where o.owner_id = #{userId} and o.room_status = 1  GROUP BY c.community_name,c.community_id")
    List<ZyCommunity> selectAllByOwnerId(String userId);

}
